package system.logic;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

//import system.dto.systemDto;
import system.dto.LoginDto;
import system.value.LoginValue;

public class LoginLogic {
	private static Connection getConnection() throws Exception {
        Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver").newInstance();
        String l_url = "jdbc:sqlserver://127.0.0.1:1433;databasename=gz";
        String l_user = "admin";
        String l_password = "admin";
        Connection l_conn = DriverManager
            .getConnection(l_url, l_user, l_password);
        return l_conn;
    }
	
	public void checkLogin(LoginDto l_dto) throws Exception {
		LoginValue l_value = l_dto.getLoginValue();
		System.out.println("xxxxxxxxx"+l_value.getUsername());
		Connection l_conn = getConnection();
		String l_sql = "select username,password from manager where username='"
			+ l_value.getUsername()	+ "' and password='"
			+ l_value.getPassword()	+ "'";
		PreparedStatement l_preStatement = l_conn.prepareStatement(l_sql);
        ResultSet l_resultSet = l_preStatement.executeQuery();
        if(l_resultSet.next()){
        	l_value.setFlag("2");
        }else{
        	l_value.setFlag("1");
        }
        l_dto.setLoginValue(l_value);
	}
}
